<?php

class Session {
    
    public static $id;
    
    public static  function start(){
         session_start();
         Session::$id = session_id();
         $s = new Session();         
         $s->updateId(  );
        /*if( $userId != 0 ){
            session_id( $userId );
            session_start();
        } */      
    }
    
    private function updateId(){
        if(isset($_SESSION['auth']) &&  !isset($_SESSION['sess']['upd'])){
            $sql = "UPDATE `".PREFIX_TABLE."users` SET `sessid` = '".Session::$id."' WHERE `kontaktid` = '".$_SESSION['userId']."' ";
            DBConnect::query($sql);
            $_SESSION['sess']['upd'] = 1;
        }
    }
    
    public function deleteAllSession($admin = 0){
        
        /*$sql = "SELECT `sessid` FROM `".PREFIX_TABLE."users` WHERE `kontaktid` != '".$admin."' ";        
        if( !$result = DBConnect::query($sql) ) return false ;
        while($arr = DBConnect::getOne($result)){            
            _echo(session_save_path()."/sess_".$arr['sessid']);
            chmod(session_save_path()."/sess_".$arr['sessid'], 0777);
            unlink(session_save_path()."/sess_".$arr['sessid'] );             
        }*/
        DBConnect::query("UPDATE `".PREFIX_TABLE."users` SET `sessid` = '' ");
        return true;
    }
    
    public function deleteMySession(){        
        foreach( $_SESSION as $k => $v ){
            if($k != 'authAdmin') unset($_SESSION[$k]);
        }
    }
    
}

?>